import Hello from '../components/Hello';
import * as actions from '../actions';
import { StoreState } from '../types/index';
import { connect, Dispatch } from 'react-redux';

/* 
  将当前的store的数据作为消息传给我们组件需要shape
*/
export function mapStateToProps({ languageName, enthusiasmLevel }: StoreState) {
  return {
    enthusiasmLevel: enthusiasmLevel,
    name: languageName,
  }
}

/* 
  可以创建回调属性来使用“dispatch”函数将行为推送到我们的store
*/
export function mapDispatchToProps(dispatch: Dispatch<actions.EnthusiasmAction>) {
  return {
    onIncrement: () => dispatch(actions.incrementEnthusiasm()),
    onDecrement: () => dispatch(actions.decrementEnthusiasm())
  }
}

/* 
```connect```将首先使用```mapStateToProps```和```mapDispatchToProps```，
然后返回另一个可以用来包装组件的函数。
*/
export default connect(mapStateToProps, mapDispatchToProps)(Hello);

